package model;

import controller.DataBaseInteactor;

/**
 * A class the will be used to login.
 * @author Rahel Ephrem
 * @edit   Richard Lee
 * @version 05/21/2013
 * 
 */
public class LogIn {

	/**
	 * User name.
	 */
	private String userId;

	/**
	 * user password.
	 */
	private String password;

	/**
	 * first name of a user.
	 */
	private String firstName;

	/**
	 * last name of a user.
	 */
	private String lastName;

	/**
	 * Confirmed password input for the register.
	 */
	private String comfPassword;

	/**
	 * conference that relates to a user.
	 */
	private Conference conf;

	/**
	 * a role of a user.
	 */
	private String role;

	/**
	 * Name of the conference
	 */
	private String confName;
	/**
	 * create an object to access DataBaseInteactor class.
	 */
	DataBaseInteactor interactor;

	/**
	 * a login contractor allows to login with appropriate conference and role.
	 * 
	 * @param userId
	 *            a user name.
	 * @param password
	 *            a user password.
	 * @param conf
	 *            a conference that a user able to view.
	 * @param role
	 *            the role of a user.
	 */
	public LogIn(String userId, String password, Conference conf, String role, DataBaseInteactor inputInteactor) {
		this.interactor = inputInteactor;
		this.userId = userId;
		this.password = password;
		this.conf = conf;
		this.role = role;
	}

	/**
	 * create a user for the first time with it's role.
	 * 
	 * @param inputID
	 *            user login name
	 * @param inputPW
	 *            password of the user
	 * @param inputComfPw
	 *            confirm the password
	 * @param inputFirstName
	 *            first name
	 * @param inputLastName
	 *            last name of a user
	 * @param inputRole
	 *            what role is the user registering
	 */
	public LogIn(String inputID, String inputPW, String inputComfPw,
			String inputFirstName, String inputLastName, String inputRole, String inputConf,
			DataBaseInteactor inputInteactor) {
		this.interactor = inputInteactor;
		this.userId = inputID;
		this.password = inputPW;
		this.comfPassword = inputComfPw;
		this.firstName = inputFirstName;
		this.lastName = inputLastName;
		this.confName = inputConf;
		this.role = inputRole;
	}

	/**
	 * verify if the user can login to the system.
	 * @param name user name
	 * @param password password of a user
	 * @param comfPassword confirm the password
	 */
	public LogIn(String name, String password, String comfPassword) {
		this.userId = name;
		this.password = password;
		this.comfPassword = comfPassword;
	}

	/**
	 * A method that verifies if a user is on the list.
	 * @param nameId user name
	 * @param password user password
	 * @return true/false based on the list.
	 */
	public boolean login() {
		boolean found = false;
		found = interactor.validLogin(userId, password, conf.getName(), role);
		return found;
	}

	/**
	 * add a user to a user database.
	 */
	public boolean newUser() {
		//id, last, first, confName, role, pw
		boolean res;
		if (password.equals(comfPassword)) {
			interactor.newUser(userId, lastName, firstName, confName, role, password);
			res = true;
		} else {
			res = false;
		}
		return res;
		
	}

	/**
	 * set the userId.
	 * @param userId a userId
	 */
	public void setUserId(final String userId) {
		this.userId = userId;
	}

	/**
	 * get a user Id.
	 */
	public String getUserId() {
		return userId;
	}

	/**
	 * set the password.
	 * @param userId a userId
	 */
	public void setPassword(final String password) {
		this.password = password;
	}

	/**
	 * get a password.
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * set the first name.
	 * 
	 * @param userId
	 *            a userId
	 */
	public void setfirstName(final String firstName) {
		this.firstName = firstName;
	}

	/**
	 * get a a first name.
	 */
	public String getfirstName() {
		return firstName;
	}

	/**
	 * set the last name.
	 * 
	 * @param userId
	 *            a userId
	 */
	public void setLastName(final String lastName) {
		this.lastName = lastName;
	}

	/**
	 * get a a last name.
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * set the last name.
	 * 
	 * @param userId
	 *            a userId
	 */
	public void setRole(final String role) {
		this.role = role;
	}

	/**
	 * get a a last name.
	 */
	public String getRole() {
		return role;
	}

	/**
	 * set a conference for a user.
	 * 
	 * @param userId
	 *            a userId
	 */
	public void setConf(final Conference conf) {
		this.conf = conf;
	}

	/**
	 * get a a conference.
	 */
	public Conference getConf() {
		return conf;
	}

}
